import java.util.Arrays;

public class SolutionInterview10_1 {
    public void merge(int[] A, int m, int[] B, int n) {
        int[] t=new int[A.length];
        int x=0,y=0,c=0;
        while (x<m && y<n){
            if (A[x]<B[y]){
                t[c++]=A[x++];
            }else {
                t[c++]=B[y++];
            }
        }
        while (x<m){
            t[c++]=A[x++];
        }
        while (y<n){
            t[c++]=B[y++];
        }
        System.arraycopy(t, 0, A, 0, A.length);
    }

    public static void main(String[] args) {
        int[] A=new int[]{1,2,3,0,0,0};
        int[] B=new int[]{2,5,6};
        new SolutionInterview10_1().merge(A,3,B,3);
        System.out.println(Arrays.toString(A));
    }

}
